package org.sfgeeq.hello;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 1、继承了HttpServlet，让它成为一个servlet类212121
 * 2、覆盖父类doGet方法，用于接收GET请求
 * 3、在doGet方法中获取 系统时间，并将其放入HttpServletRequest 对象中，最后转发到/WEB-INF/jsp/hello.jsp 页面
 * 4、使用 WebServlet注解并配置请求路径，对外发布servlet服务
 *
 * Created by Administrator on 2016/5/13.
 */
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
        SimpleDateFormat date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime=date.format(new Date());
        req.setAttribute("currentTime",currentTime);
        req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req,resp);

    }


}
